﻿#include<iostream>
#include<random>
using namespace std;

int r, g, b;

int ans[11][11][11];


void swap(int& a, int& b) {
	int t;
	t = a;
	a = b;
	b = t;
}

void max(int& a, int& b) {
	if(a < b)swap(a,b);
}

void sort(int& a, int& b, int& c) {
	max(a, b);
	max(b, c);
	max(a, b);
}

int main(){
	cout << "请输入样本数:";
	int mod;
	cin >> mod;
	random_device seed;//硬件生成随机数种子
	ranlux48 engine(seed());//利用种子生成随机数引擎
	uniform_int_distribution<> distrib(0, 2);//设置随机数范围，并为均匀分布
	for (int i = 0; i <= mod; ++i) {
		r = 0;
		g = 0;
		b = 0;
		for (int j = 0; j < 9; ++j) {
			int a = distrib(engine);
			if (a == 0) {
				r++;
			}
			else if (a == 1) {
				g++;
			}
			else if (a == 2) {
				b++;
			}
		}
		sort(r, g, b);
		ans[r][g][b]++;
	}
	cout <<"模拟次数:"<<mod<<endl<< "统计结果：" << endl;
	ans[2][3][4] = ans[4][3][2];
	ans[4][3][2] = 0;
	double num_ = 0;
	for (int i = 0; i <= 9; ++i) {
		for (int j = 0; j <= 9; ++j) {
			for (int k = 0; k <= 9; ++k) {
				double num = ans[i][j][k];
				if (num == 0)continue;
				
				num = double(num) / double(mod) ;
				num_ += num;
				num = double(num) * double(100.0);
				cout << i << " " << j << ' ' << k << ":         " << num << '%' << endl;
			}
		}
	}
	cout << "end";
	return 0;
}